<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@taglib prefix="pu" uri="/WEB-INF/tld/pageutil.tld" %>
<%@taglib prefix="mu" uri="/WEB-INF/tld/mallutil.tld" %>
<%@taglib prefix="pageable" uri="/WEB-INF/tld/pageable.tld" %>
<%@taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c-rt"%>
<%@taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt-rt"%>
<%@taglib uri="http://www.yaodian100.com/jsp/yaodian100" prefix="yaodian100" %>
<%@page import="com.yaodian100.core.common.utils.ServerValue"%>
<c-rt:set var="imgDomain"><%=ServerValue.getImgDomain()%></c-rt:set>
<!-- mn --> 
<script>
<yaodian100:specSelectJs addOnProdTypeInvMap="${addOnProdTypeInvMap['nm']}" prodSpecMajorMap="${prodSpecMajorMap}" addOnProdTypes="${addOnProdTypeMap['nm']}"/>
</script>

<div class="pd-nm pdlong">
	<h5>任選 <strong>${product.pickupQty}</strong> 件 
		<strong>
			<c-rt:if test="${!empty shelf.shelfPrice}">￥<fmt-rt:formatNumber value="${shelf.shelfPrice}"  pattern="####0.0"/></c-rt:if>
		</strong>
	</h5>
	<ul>
	<c-rt:if test="${not empty addOnProdTypeMap['nm']}">
  	<c-rt:forEach items="${addOnProdTypeMap['nm']}" var="addOnProduct" varStatus="nmStatus">
      <c-rt:set var="url">/product/addOnProductInfo.do?productId=${product.productId}&addOnProductId=${addOnProduct.addOnProductId}</c-rt:set>
			<c-rt:set var="inventorySum" value="0"/>
			<c-rt:set var="specsCount" value="0"/>
	      <c-rt:forEach items="${prodSpecMap[addOnProduct.addOnProductId]}" var="spec" varStatus="idx">
					<c-rt:set var="inventorySum">${inventorySum + addOnProdTypeInvMap['nm'][spec.specificationId]}</c-rt:set>
					<c-rt:set var="specsCount">${idx.count}</c-rt:set>
			</c-rt:forEach>
			<c-rt:if test="${inventorySum>0}">
				<c-rt:set var="hasInventory" value="true"/>
				<c-rt:set var="nmClassName" value=""/>
			</c-rt:if>
			<c-rt:if test="${inventorySum ==0}">
				<c-rt:set var="hasInventory" value="false"/>
			</c-rt:if>
			<c-rt:if test="${specsCount>0}">
      <li class="${nmClassName}" id="nmBox_${addOnProduct.addOnProductId}">
      	<c-rt:url value="/product/nmDetail.do?productId=${addOnProduct.addOnProductId}&nmProductId=${product.productId}&index=${addOnProduct.addOnProductId}" var="urlPath"/>
      	<a href="javascript:;">
      		<img src="${imgDomain}/PImg/${pu:substring(addOnProduct.addOnProductId, 0,4)}/${addOnProduct.addOnProductId}/${addOnProduct.addOnProductId }_rm225.jpg" onError="this.src='/PImg/blank_r225.gif'" alt="" width="170" height="225" onClick="window.open('${urlPath}&mId='+$('#selectMs_${addOnProduct.addOnProductId}').val()+'&sId='+$('#selectSs_${addOnProduct.addOnProductId}').val(),'','width=950,height=620,directories=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=no,left=50,top=50');return false;"/>
      	</a>
      	<em>${addOnProduct.addOnDesc}</em> 
				<h6><a href="javascript:;" onClick="window.open('${urlPath}','','width=950,height=620,directories=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=no,left=50,top=50');return false;">
					${addOnProduct.productName}
				</a></h6>
                  <c-rt:if test="${empty nmProdCommentMap}">
		             <div class="s-box star-0-0">
			       	  	用户评分：<span class="sr1"></span><span class="sr2"></span><span class="sr3"></span><span class="sr4"></span><span class="sr5"></span><br /><cite>(还没有用户评分)</cite>
			       	  </div> 
		       	 </c-rt:if>
		       	  <c-rt:if test="${not empty nmProdCommentMap}">
			       	   <div class="s-box star-<fmt-rt:formatNumber value="${nmProdCommentMap[addOnProduct.addOnProductId].avgScore}" pattern="#0"/>-${(nmProdCommentMap[addOnProduct.addOnProductId].avgScore*10)%10>0?'5':'0'}"> 
						用户评分：<span class="sr1"></span><span class="sr2"></span><span class="sr3"></span><span class="sr4"></span><span class="sr5"></span><br /><cite>${nmProdCommentMap[addOnProduct.addOnProductId].avgScore}分&nbsp;(<a href="#productRating">已有${nmProdCommentMap[addOnProduct.addOnProductId].totalRecord}人评价</a>)</cite>
		               </div> 
		       	  </c-rt:if>
				
				
        <c-rt:if test="${hasInventory!='true'}">         
         	<span>已售完补货中</span>         
        </c-rt:if>
        <c-rt:if test="${hasInventory=='true'}">
        	<script language="javascript">
						haveInventory=true;
					</script>
				
				<yaodian100:specSelect mainCodeLabel="${addOnProduct.mainCodeLabel}" secondCodeLabel="${addOnProduct.secondCodeLabel}" productId="${addOnProduct.addOnProductId}" productSpecMajors="${prodSpecMajorMap[addOnProduct.addOnProductId]}"/>	       		
	        	<span><input class="addOnProductNm" id="addOnProductNm_${addOnProduct.addOnProductId}" name="addOnProductNm" type="checkbox" value="${addOnProduct.addOnProductId }_#spec#_1_${aoproduct.mainCategoryID}_6_<%=application.getContextPath() %>">我要选购<b>&nbsp;</b></span>
        </c-rt:if>
      </li>
      </c-rt:if>
    </c-rt:forEach>
    </c-rt:if>
	</ul>
</div>
<div class="pdnminfo">
	<p><strong>目前已选购 <em><b id="hasChecked">0</b></em>件</strong> (请任选<em> ${product.pickupQty } </em>件)</p>
	
	
  	<c-rt:if test="${product.isDelete!='Q'}">
  		<c-rt:choose>
	   		<c-rt:when test="${product.productType eq '7'}">
	   			<a href="###" class="buy-main" onclick="${toBuyMethod}" title="立即购买" style="cursor: pointer;cursor:hand;display:none;">立即购买<b>&nbsp;</b></a>
	   		</c-rt:when>
	   		<c-rt:otherwise>
		    	<a class="buy-main" href="###" onclick="${toBuyMethod}" title="立即购买" style="cursor: pointer;cursor:hand;display:none;">立即购买<b>&nbsp;</b></a>
		   		<c-rt:if test="${(empty product.nmMustOrderBuy or product.nmMustOrderBuy eq 'N') and !hasAndeProduct}">
		   			<c-rt:if test="${!(product.productType=='1')}">
		    			<a href="###" class="buy-car" onclick="${toAddCartMethod}" title="加入购物车！" style="cursor: pointer;cursor:hand;display:none;">加入购物车<b>&nbsp;</b></a>
		    		</c-rt:if>
		    	</c-rt:if>
		   		<c-rt:if test="${product.nmMustOrderBuy eq 'Y' and product.productType ne '6' and !hasAndeProduct}">
		   			<a href="###" class="buy-car" onclick="${toAddCartMethod}" title="加入购物车！" style="cursor: pointer;cursor:hand;display:none;">加入购物车<b>&nbsp;</b></a>
		   		</c-rt:if>
			 	</c-rt:otherwise>
			</c-rt:choose>
      <c-rt:if test="${resultDaphne['isDaphne'] and resultDaphne['invDaphne'] and product.isScm eq 'N'}">
			 	<a class="buy-daphne" href="###" onclick="${toBuyDaphneMethod}" style="cursor: pointer;cursor:hand;display:none;" title="门店取货！">门店取货<b>&nbsp;</b></a>
			</c-rt:if>		 	
			<c-rt:if test="${product.productType!='1' and product.isScm=='N' or (resultDaphne['isDaphne'] and !resultDaphne['invDaphne']) }">
				<div class="arr-tellme" style="display:none;"><p>
					<c-rt:choose>
						<c-rt:when test="${product.showArrival}">
							预计<strong><fmt-rt:formatDate value="${product.arrivalDate}" pattern="yyyy-MM-dd"/></strong>到货
						</c-rt:when>
						<c-rt:otherwise>厂商火速补货中</c-rt:otherwise>
					</c-rt:choose>
					<br><a id="addRestockRemind_${product.productId }_${product.listPrice }" href="javascript:;">貨到通知我<b>&nbsp;</b></a>
				</div>				
			</c-rt:if>
  	</c-rt:if>
    <c-rt:if test="${product.isDelete=='Q'}">
    		<a title="即将开卖" class="coming-soon" href="javascript:;">即将开卖<b>&nbsp;</b></a>
            <a title="即将开卖商品无法加入购物车，请使用「加入收藏盒」功能！" class="buy-car-no" href="javascript:;">加入购物车<b>&nbsp;</b></a>
		</c-rt:if>
  
</div>
<!-- mn --> 
<script language="javascript">
	//IE下不能disabled掉select标签的option的解决方案
	window.onload = function() {  
	    if (document.getElementsByTagName) {  
	        var s = document.getElementsByTagName("select");  
	  
	        if (s.length > 0) {  
	            window.select_current = new Array();  
	  
	            for (var i=0, select; select = s[i]; i++) {  
	                select.onfocus = function(){ window.select_current[this.id] = this.selectedIndex; }  
	                select.onchange = function(){ restore(this); }  
	                emulate(select);  
	            }  
	        }  
	    }  
	}  
	  
	function restore(e) {  
	    if (e.options[e.selectedIndex].disabled) {  
	        e.selectedIndex = window.select_current[e.id];  
	    }  
	}  
	  
	function emulate(e) {  
	    for (var i=0, option; option = e.options[i]; i++) {  
	        if (option.disabled) {  
	            option.style.color = "graytext";  
	        }  
	        else {  
	            option.style.color = "menutext";  
	        }  
	    }  
	}
	var nmCount=0;
	var nmAt=0;
	$(function(){
		$(":input[id*='selectSs_']").change(function(){
			id=$(this).attr('id');
			index=id.replace('selectSs_', '');
			if($(this).val() != ""){
				$("#addOnProductNm_" + index).attr('checked',true);
				$('#nmBox_'+index).attr('class', 'nm-f');
			}else{
				$("#addOnProductNm_" + index).attr('checked',false);
				$('#nmBox_'+index).attr('class', '');
			}
			selectNm2(index,$(this).val());
		});
		$(":select[id*=selectMs_]").change(function(){
			var index = $(this).attr('id').split('_')[1];
			$("#selectSs_"+index).change();
		});
		$('.addOnProductNm').each(function(){
			id=$(this).attr('id');
			index=id.replace('addOnProductNm_', '');
			if($(this).attr('selected')){
				$('#nmBox_'+index).attr('class', 'nm-f');
			}else{
				$('#nmBox_'+index).attr('class', '');
			}
			$(this).click(function(){
				id=$(this).attr('id');
				index=id.replace('addOnProductNm_', '');
				if($('#selectSs_'+index).attr('value')==''){
					alertDialog('讯息','请先选择属性');
					$(this).attr('checked', false);
					return;
				}else{
						nmCount=0;
						$('.addOnProductNm').each(function(){
							if($(this).attr('checked')){
								nmCount++;
							}	
						});
						if(nmCount>${product.pickupQty}){
							alertDialog('讯息', '已经选择${product.pickupQty}件');
							$(this).attr('checked', false);
							nmCount--;
							return;
						}else{
							$('#hasChecked').html(nmCount);
						}
				}
				if($(this).attr('checked')){
					$('#nmBox_'+index).attr('class', 'nm-f');
				}else{
					$('#nmBox_'+index).attr('class', '');
					$('#selectMs_'+index)[0].selectedIndex = 0;
					if($('#selectMs_'+index).val()=='请选择'){
						$('#selectMs_'+index).change();
					}else{
						$('#selectSs_'+index)[0].selectedIndex = 0;
					}
				}
			});
		});
		$('.addOnProductNm').each(function(){
			if($(this).attr('checked')){
				nmCount++;
			}	
		});
		$('#hasChecked').html(nmCount);
	});
	function selectNm(index, mspecId, specId){
		$('#selectMs_'+index).attr('value', mspecId);
		$('#selectMs_'+index).change();
		$('#selectSs_'+index).attr('value', specId);
		$('#nmBox_'+index).attr('class', 'nm-f');
		$('#addOnProductNm_'+index).attr('checked', true);
				nmCount=0;
				$('.addOnProductNm').each(function(){
					if($(this).attr('checked')){
						nmCount++;
					}	
				});
				if(nmCount>${product.pickupQty}){
					alertDialog('讯息', '已经选择${product.pickupQty}件');
					$('#selectSs_'+index)[0].selectedIndex = 0;
					$('#addOnProductNm_'+index).attr('checked', false);
					$('#nmBox_'+index).attr('class', '');
					nmCount--;
				}else{
					$('#hasChecked').html(nmCount);
				}
	}
	function selectNm2(index, specId){
				nmCount=0;
				$('.addOnProductNm').each(function(){
					if($(this).attr('checked')){
						nmCount++;
					}	
				});
				if(nmCount>${product.pickupQty}){
					alertDialog('讯息', '已经选择${product.pickupQty}件');
					$('#selectSs_'+index)[0].selectedIndex = 0;
					$('#addOnProductNm_'+index).attr('checked', false);
					$('#nmBox_'+index).attr('class', '');
					nmCount--;
				}else{
					$('#hasChecked').html(nmCount);
				}
	}
</script>